package com.atguigu.day08.p6;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/8 16:04
 * @注释
 */
public class Triangle {
    private double a;
    private double b;
    private double c;

    public Triangle() {
    }

    public Triangle(double a) {
        this.a = a;
    }

    public Triangle(double a, double b) {
        this.a = a;
        this.b = b;
    }

    public Triangle(double a, double b, double c) {
        setBases(a, b, c);
    }

    public void setBases(double a, double b, double c) {
        if (a > 0 && b > 0 && c > 0 && (a + b > c && a + c > b && b + c > a)) {
            this.a = a;
            this.b = b;
            this.c = c;
        } else {
            System.out.println("您所输入的三条边不能构成三角形");
        }
    }

    /*public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }*/
    public double area() {
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }

    public double perimeter() {
        return a + b + c;
    }

    public String getInfo() {
        return "三条边分别是: " + a + " " + b + " " + c + "\n"
                + "面积: " + area() + "\n" + "周长是: " + perimeter();
    }
}
